// require用于从外部获取模块接口其实获取的就是模块的exports对象
const export1 = require('./static/exports1');
console.log(export1);// { attr1: 'attr1', attr2: 'attr2', func: [Function: func], attr3: 'attr3' }
console.log(export1.attr1);// attr1
console.log(export1.attr2);// attr2
console.log(export1.attr3);// attr3
console.log(export1.func('hello'));// func hello
/**
 * exports1内容如下
 * exports.attr1 = 'attr1';
 *
 * module.exports.attr2 = 'attr2';
 * module.exports.func = function func(val) {
 *   return 'func ' + val;
 * };
 *
 * exports.attr3 = 'attr3';
 */

// module.exports可简写为exports
console.log(module.exports === exports);// true


// 向外暴露的永远都是module.exports对象
const export2 = require('./static/exports2');
console.log(export2);// { attr2: 'attr2', func: [Function: func] }
console.log(export2.attr1);// undefined
console.log(export2.attr2);// attr2
console.log(export2.attr3);// undefined
console.log(export2.func('hello'));// func hello
/**
 * exports2内容如下
 * exports.attr1 = 'attr1';
 *
 * module.exports = {
 *   attr2: 'attr2',
 *   func: function (val) {
 *     return 'func ' + val;
 *   }
 * };
 *
 * exports.attr3 = 'attr3';
 */